<?php
include("config.php");
$results = mysql_query("SELECT * FROM admin_settings");

while ($row = mysql_fetch_array($results)) {
        $rss_tab_1_address = $row["rss_tab_1_address"];
        $rss_tab_2_address = $row["rss_tab_2_address"];
	$num_rss_display = $row["num_rss_display"];
}


/*
	This file will parse RSS/XML feeds and display the content
	
	TODO:  This file has a user option for the number of RSS entries to display
*/

//get the q parameter from URL
$q=$_GET["q"];

//find out which feed was selected
if($q=="Google")
  {
  $xml=("http://news.google.com/news?ned=us&topic=h&output=rss");
  }
elseif($q=="MSNBC")
  {
  $xml=("http://rss.msnbc.msn.com/id/3032091/device/rss/rss.xml");
  }
elseif($q=="tab2")
  {
  $xml=("$rss_tab_2_address");
  }
elseif($q=="tab1")
  {
  $xml=("$rss_tab_1_address");
  }

$xmlDoc = new DOMDocument();
$xmlDoc->load($xml);

//get elements from "<channel>"
$channel=$xmlDoc->getElementsByTagName('channel')->item(0);
$channel_title = $channel->getElementsByTagName('title')
->item(0)->childNodes->item(0)->nodeValue;
$channel_link = $channel->getElementsByTagName('link')
->item(0)->childNodes->item(0)->nodeValue;
$channel_desc = $channel->getElementsByTagName('description')
->item(0)->childNodes->item(0)->nodeValue;

//output elements from "<channel>"
//echo("<p><a href='" . $channel_link
//  . "'>" . $channel_title . "</a>");
//echo("<br />");
//echo($channel_desc . "</p>");

//get and output "<item>" elements
$x=$xmlDoc->getElementsByTagName('item');
for ($i=0; $i<$num_rss_display; $i++)
  {
  $item_title=$x->item($i)->getElementsByTagName('title')
  ->item(0)->childNodes->item(0)->nodeValue;
  $item_link=$x->item($i)->getElementsByTagName('link')
  ->item(0)->childNodes->item(0)->nodeValue;
  $item_desc=$x->item($i)->getElementsByTagName('description')
  ->item(0)->childNodes->item(0)->nodeValue;
  $item_date=$x->item($i)->getElementsByTagName('pubDate')
  ->item(0)->childNodes->item(0)->nodeValue;

  echo ("<p><a href='" . $item_link
  . "' target='_blank'>" . $item_title . "</a>");
  echo ("<br />");
  echo ("<i>" . $item_date . "</i><br />");
  echo ($item_desc . "</p>");
  }
?> 
